package com.ymatou.iapi.productmanager.testcase;

import com.google.common.reflect.TypeToken;
import com.google.gson.JsonArray;
import com.ymatou.iapi.prodstock.parameter.ModifyResult;
import com.ymatou.iapi.productmanager.parameter.GetFBXCatalogsByUserIdBean;
import com.ymatou.iapi.productmanager.service.GetFBXCatalogsByUserIdCall;
import com.ymt.core.tool.FormatUtil;
import com.ymttest.database.sqlwapper.YmtProductsIWapper;
import org.apache.commons.lang3.StringUtils;
import org.joda.time.format.FormatUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
*查询买手使用过的sku
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetFBXCatalogsByUserId{
	private static GetFBXCatalogsByUserIdBean getfbxcatalogsbyuseridBean;
	private static GetFBXCatalogsByUserIdCall getfbxcatalogsbyuseridCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("查询买手使用过的sku");
	}

	@Before
	public void caseUp() {
		getfbxcatalogsbyuseridBean=new GetFBXCatalogsByUserIdBean();
		getfbxcatalogsbyuseridCall=new GetFBXCatalogsByUserIdCall();
	}
	

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getfbxcatalogsbyuseridCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetFBXCatalogsByUserId_01() {
		Logger.start(true,"查询买手使用过的sku");
		try {
			getfbxcatalogsbyuseridBean.setUserId(3383);
			getfbxcatalogsbyuseridCall.setData(getfbxcatalogsbyuseridBean);
			getfbxcatalogsbyuseridCall.callService();
			String FBXSkuList = getfbxcatalogsbyuseridCall.getJsonObject().get("Data").getAsJsonObject().get("FBXSkuList").getAsJsonArray().toString();
			List<String> FBXSKU=(List<String>) FormatUtil.GSONToObject(FBXSkuList, new TypeToken<List<String>>(){}.getType());
			List<String> list = new YmtProductsIWapper().GetFBXCatalogsByUserId(3383).stream().filter(x-> StringUtils.isNotBlank(x)).collect(Collectors.toList());
			Logger.verifyEquals(true,isListEqual(FBXSKU,list),"验证是否与数据库一致");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}


	public static boolean isListEqual(List l0, List l1){
		if (l0 == l1)
			return true;
		if (l0 == null && l1 == null)
			return true;
		if (l0 == null || l1 == null)
			return false;
		if (l0.size() != l1.size())
			return false;
		for (Object o : l0) {
			if (!l1.contains(o))
				return false;
		}
		for (Object o : l1) {
			if (!l0.contains(o))
				return false;
		}
		return true;
	}

}